package com.zui.util;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * external paging for jqGrid.
 * 
 * @author zhaoyongPaginatedListImpl.java
 */
public class JQGridListImpl extends ArrayList<Object> implements JQGridList,Serializable {
	private static final long serialVersionUID = 1L;

	public JQGridListImpl() {
	}

	/**
	 * "return this" generates"Cyclic reference detected on..."
	 * @return
	 */
	public List<?> getList() {
			return this;
	}
	/**
	 * the number of objects requested, no getter, no JSON serialization.
	 */
	private int objectsPerPage = Page.PAGE_SIZE;
	//public int getObjectsPerPage() {return objectsPerPage;}
	public void setObjectsPerPage(int pageSize) {this.objectsPerPage = pageSize;}
	/**
	 *  current page number
	 */
	private int page = 0;
	public int getPage() {return page;}
	public void setPage(int page) {this.page = page;	}
	/**
	 * total page number
	 */
	private int total = 0;
	public int getTotal() {return total;}
	public void setTotal(int total) {this.total = total;}
	/**
	 *  total records number
	 */
	private int records = 0;
	public int getRecords() {return records;}
	public void setRecords(int records) {
		this.records = records;
		if (this.records > 0 && objectsPerPage > 0) {
			this.total = (int) Math.ceil((double) this.records
					/ (double) objectsPerPage);
		} else {
			this.total = 0;
		}
	}
}